package com.vcs.frm.web;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.vcs.frm.domain.Job;
import com.vcs.frm.service.common.CommonService;

@Controller
public class HomeController {

	private final Logger log = Logger.getLogger(this.getClass());
	
	@Autowired
	private CommonService commonService;
	
	public HomeController() {
		
	}

	@RequestMapping({"/","/home"})
	public ModelAndView welcomeHandler(Model model, HttpSession session ) {
		
		log.info("method - welcomeHandler ");
		ModelAndView mav = new ModelAndView();
		
		/* 1. Fetch top 3 recently posted jobs on the site. */
		List<Job> recentJobs = commonService.getRecentJobs(3);
		mav.addObject("recentJobs",recentJobs);
		/* 2. Fetch top 3 recently joined clients */
		mav.setViewName("home");
		
		return mav;
	}

	@RequestMapping("/vcs")
	public String defaultHandler(Model model) {
		log.info("---------- defaultHandler ");
		return "home";
	}
}
